import { Injectable, Inject, Delete } from '@nestjs/common';
import { Model } from 'mongoose';
import {User} from './interfaces/user.interface'
import { InjectModel } from '@nestjs/mongoose';
@Injectable()
export class AppService {
    constructor(
        @InjectModel('User')
        private readonly userModel:Model<User>
    ){}

    private static users:User[] = []
    async getHello(): Promise<User[]> {
        return await this.userModel.find()
    }

    async insert(): Promise<User[]> {
        let res = await this.userModel.insertMany({'name':'123'})
        console.log(res)
        return await this.userModel.find()
    }

    async update(): Promise<User[]> {
        let res = await this.userModel.update({'name':'123'},{$set:{'name':'修改过后的名字'}})
        console.log(res)
        return await this.userModel.find()
    }
    async deleteOne(): Promise<User[]> {
        let res = await this.userModel.deleteOne({'name':'123'})
        console.log(res)
        return await this.userModel.find()
    }

}
